<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="box">
        <input type="text" v-model="msg">
        <br>
        <input type="text" v-model="deepObj.name">
        <br>
        <input type="text" v-model="userObj.name">
    </div>
    <script src="./js/vue.js"></script>
    <script>
        let vm = new Vue({
            el:"#box",
            data:{
                msg:"hello",
                deepObj:{name:'张三'},
                userObj:{name:'张三'}
            },
            computed:{
                newName(){
                    return this.userObj.name;
                }
            },
            watch:{
                msg:function(newValue,oldValue){
                    console.log("watch-msg:",newValue,oldValue);
                },
                // 对象属性发生变化时，监听不到
                // deepObj(newValue,oldValue){
                //     console.log("watch-deepObj");
                // }
                deepObj:{
                    handler(newValue,oldValue){
                        console.log("watch-deepObj",newValue.name,oldValue.name);
                    },
                    deep:true // 默认是false , true 表示深度侦听
                },
                newName(newValue,oldValue){
                    console.log("watch-newName:",newValue,oldValue);
                }
            }
        })
    </script>
</body>
</html>